package com.xxrl.hmwork.controller;

import com.xxrl.hmwork.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 统计数据
 * @author mis
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    private final StatisticsService statisticsService;

    public StatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    @GetMapping("count")
    public Map<String,Long> count() {
        Map<String, Long> map = new HashMap<>(4);
        map.put("visitCount",statisticsService.totalVisit);
        map.put("homeworkCount", statisticsService.totalHomework);
        map.put("fileCount", statisticsService.totalFiles);
        map.put("userCount", statisticsService.totalUser);
        return map;
    }

    @GetMapping("homeworkCount")
    public Long homework() {
        return statisticsService.totalHomework;
    }

    @GetMapping("visitCount")
    public Long[] visit(
            @RequestParam(name = "type") Integer type) {
        return statisticsService.visit[type];
    }
}
